package model;

import com.et.ar.ActiveRecordBase;
import com.et.ar.annotations.Column;
import com.et.ar.annotations.Id;
import com.et.ar.annotations.Table;
import com.et.ar.exception.ActiveRecordException;
import com.wzzz.cache.CacheHandler;
import com.wzzz.util.StringUtil;

@Table(name = "T_CASE_SHELF_INFO")
public class CaseShelfInfo extends ActiveRecordBase {
	@Id
	private String shelf_id; // 保管柜ID
	@Column
	private String shelf_num; // 保管柜编号
	@Column
	private String shelf_name; // 保管柜名称
	@Column
	private String shelf_begin_date; // 保管柜启用时间
	@Column
	private String shelf_status; // 保管柜使用状态
	@Column
	private String shelf_coment; // 保管柜备注信息
	@Column
	private String shelf_row; // 保管柜行
	@Column
	private String shelf_con; // 保管柜列
	@Column
	private String shelf_format; // 保管柜展示方式
	@Column
	private String shelf_type; // 保管柜类型
	@Column
	private String case_room_id; // 保管室ID

	public String getShelf_id() {
		return shelf_id;
	}

	public void setShelf_id(String shelf_id) {
		this.shelf_id = shelf_id;
	}

	public String getShelf_num() {
		return shelf_num;
	}

	public void setShelf_num(String shelf_num) {
		this.shelf_num = shelf_num;
	}

	public String getShelf_name() {
		return shelf_name;
	}

	public void setShelf_name(String shelf_name) {
		this.shelf_name = shelf_name;
	}

	public String getShelf_begin_date() {
		return shelf_begin_date;
	}

	public void setShelf_begin_date(String shelf_begin_date) {
		this.shelf_begin_date = shelf_begin_date;
	}

	public String getShelf_status() {
		return shelf_status;
	}

	public void setShelf_status(String shelf_status) {
		this.shelf_status = shelf_status;
	}

	public String getShelf_coment() {
		return shelf_coment;
	}

	public void setShelf_coment(String shelf_coment) {
		this.shelf_coment = shelf_coment;
	}

	public String getShelf_row() {
		return shelf_row;
	}

	public void setShelf_row(String shelf_row) {
		this.shelf_row = shelf_row;
	}

	public String getShelf_con() {
		return shelf_con;
	}

	public void setShelf_con(String shelf_con) {
		this.shelf_con = shelf_con;
	}

	public String getShelf_format() {
		return shelf_format;
	}

	public void setShelf_format(String shelf_format) {
		this.shelf_format = shelf_format;
	}

	public String getShelf_type() {
		return shelf_type;
	}

	public void setShelf_type(String shelf_type) {
		this.shelf_type = shelf_type;
	}

	public String getCase_room_id() {
		return case_room_id;
	}

	public void setCase_room_id(String case_room_id) {
		this.case_room_id = case_room_id;
	}

	public String getRoom_statusDesc() {
		if (shelf_status != null) {
			return CacheHandler.getDicDesc("10", shelf_status);
		}
		return shelf_status;
	}

	public String getShelf_formatDesc() {
		if (shelf_format != null) {
			return CacheHandler.getDicDesc("24", shelf_format);
		}
		return shelf_format;
	}

	public String getShelf_typeDesc() {
		if (shelf_type != null) {
			return CacheHandler.getDicDesc("23", shelf_type);
		}
		return shelf_type;
	}
	
	public void afterSave() throws ActiveRecordException{
		String shelfId = this.shelf_id;
		String shelfNum = this.shelf_num;
		//生成格子信息
		//首先看柜子是几行几列的矩阵
		int rows = Integer.parseInt(this.shelf_row); 
		int cols =  Integer.parseInt(this.shelf_con);
		int count = rows*cols;
		int fillLength = (count+"").length();
		for (int i=1;i<=count;i++){
			String gridNum = StringUtil.fillLeft(i+"",'0', fillLength);
			CaseGridInfo cgi = new CaseGridInfo();
			cgi.setGrid_num(gridNum);
			cgi.setIs_using("1");
			cgi.setGrid_status("0");
			cgi.setShelf_id(shelfId);
			cgi.save();
		}
//		String format = this.shelf_format;
//		
//			for(int i=1;i<=rows;i++){
//				for(int j=1;j<=cols;j++){
//					CaseGridInfo cgi = new CaseGridInfo();
//					String gridNum;
//					if("240101".equals(format)){  //横向展示
//						gridNum = shelfNum+i+""+j+"";
//					}else{//纵向展示
//						gridNum = shelfNum+j+""+i+"";
//					}
//					cgi.setGrid_num(gridNum);
//					cgi.setIs_using("1");
//					cgi.setGrid_status("0");
//					cgi.setShelf_id(shelfId);
//					cgi.save();
//				}
//			}
	}
	
}
